package top.datacluster.basic.niukewang;


import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class EncryptByKey {

    public static String encrypt(String key, String info){
        Map<Character,Character> dict = createKey(key);
        StringBuilder result = new StringBuilder();
        char[] mes = info.toCharArray();
        for (char c : mes){
            if (c >= 'a' && c <= 'z'){
                result.append(Character.toLowerCase(dict.get(Character.toUpperCase(c))));
            }else if (c >= 'A' && c <= 'Z'){
                result.append(dict.get(c));
            }else{
                result.append(c);
            }

        }
        return result.toString();
    }

    public static Map<Character,Character> createKey(String key){
        Map<Character, Character> keyMap = new HashMap<>();
        key = key.toUpperCase();
        char[] dict = new char[]{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
                'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
        int index = 0;
        for (int i = 0; i < key.length(); i++){
            Character c = key.charAt(i);
            if (!keyMap.containsKey(c)){
                keyMap.put(c, dict[index]);
                index++;
            }
        }
        for (char c : dict){
            if (!keyMap.containsKey(c)){
                keyMap.put(c, dict[index]);
                index++;
            }
        }
        Map<Character, Character> result = new HashMap<>();
        keyMap.forEach((k, v)->{
            result.put(v, k);
        });
        return result;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            String key = scanner.nextLine();
            String info = scanner.nextLine();
            System.out.println(encrypt(key, info));
        }

    }
}
